const fp = require ('lodash/fp')
const cars = [
    {name: '111', in_stock: true, dollar_value: 3000},
    {name: '222', in_stock: false, dollar_value: 4000}
]

// 练习1
const func1 = fp.flowRight(fp.prop('in_stock'),fp.last)
console.log(func1(cars))

// 练习2
const func2 = fp.flowRight(fp.prop('name'),fp.first)
console.log(func2(cars))

// 练习3
let _average = (xs) => {
    return fp.reduce(fp.add, 0, xs)/xs.length
}
const func3 = fp.flowRight(_average,fp.map(item=>{return item.dollar_value}))
console.log(func3(cars));

// 练习4
const sanitizeNames = fp.flowRight(fp.map(fp.replace(/\s+/g, '_')),fp.map(fp.toLower))
console.log(sanitizeNames(['HEllo World']));